import { useState } from "react"; import { useRouter } from "next/router"; import { api } from "@/src/utils/api"; import Page from "@/src/components/layouts/page"; import { Button } from "@/src/components/ui/button"; import { Input } from "@/src/components/ui/input"; import { Textarea } from "@/src/components/ui/textarea"; import { Label } from "@/src/components/ui/label"; import { showSuccessToast } from "@/src/features/notifications/showSuccessToast"; import { showErrorToast } from "@/src/features/notifications/showErrorToast"; import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess"; export default function NewDashboard() { const router = useRouter(); const { projectId } = router.query as { projectId: string }; // State for new dashboard const [dashboardName, setDashboardName] = useState("New Dashboard"); const [dashboardDescription, setDashboardDescription] = useState(""); // Check project access const hasCUDAccess = useHasProjectAccess({ projectId, scope: "dashboards:CUD", }); // Mutation for creating a new dashboard const createDashboard = api.dashboard.createDashboard.useMutation({ onSuccess: (data) => { showSuccessToast({ title: "Dashboard created", description: "Your new dashboard has been created successfully", }); // Navigate to the newly created dashboard router.push(`/project/${projectId}/dashboards/${data.id}`); }, onError: (error) => { showErrorToast("Error creating dashboard", error.message); }, }); // Handle form submission const handleCreateDashboard = () => { if (dashboardName.trim()) { createDashboard.mutate({ projectId, name: dashboardName, description: dashboardDescription, }); } else { showErrorToast("Validation error", "Dashboard name is required"); } }; return ( ), }} >
{ setDashboardName(e.target.value); }} placeholder="Enter dashboard name" required />